﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Example7_Collisions.Controller
{
    class MasterController
    {
        private Model.Model m_model;
        private View.View m_view;
        private View.Camera m_camera = new View.Camera();

        public MasterController(GraphicsDeviceManager a_manager, ContentManager a_contentManager)
        {
            m_model = new Model.Model();
            m_view = new View.View(a_manager, a_contentManager);
        }

        internal void Draw(float a_elapsedTime, Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice)
        {

            //get the playerposition for the view
            Model.Level level = m_model.GetLevel();

            //update camera
            m_camera.CenterOn(m_model.GetPlayerPosition(),
                              new Vector2(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height), 
                              new Vector2(Model.Level.g_levelWidth, Model.Level.g_levelHeight));

            m_camera.SetZoom(32);

            //draw background and player 
            m_view.DrawLevel(GraphicsDevice, level, m_camera, m_model.GetPlayerPosition());
            
        }

        internal void Update(float a_elapsedTime)
        {
            //React to input
            if (m_view.DidPlayerPressJump())
            {
                //Check if jumping was OK?
                m_model.DoJump(); //realizes the jump
                
            }
            if (m_view.DidPlayerPressLeft())
            {
                m_model.MoveLeft();
            }
            if (m_view.DidPlayerPressRight())
            {
                m_model.MoveRight();
            }
            m_model.Update(a_elapsedTime);
        }


    }
}
